//
//  MyTeamVC.m
//  digitalCurrency
//
//  Created by 小震GG on 2019/11/18.
//  Copyright © 2019 XinHuoKeJi. All rights reserved.
//

#import "MyTeamVC.h"
#import "MyTeamCell.h"
#import "MyTeamSonVC.h"
@interface MyTeamVC ()

@property (nonatomic, strong) UILabel *countLB;
@property (nonatomic, strong) UIButton *cInviteBtn;
@property (nonatomic, strong) NSMutableArray *dataArr;

@end

@implementation MyTeamVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    self.view.backgroundColor = tBgQianColor;
    self.viewTitle.text = LocalizationKey(@"我的团队");
    
    self.dataArr = [[NSMutableArray alloc]init];
    
    [self setView];
}

- (void)setView{
    UIImageView *bgImage = [[UIImageView alloc]initWithFrame:CGRectMake(12, 12, kWindowW-24, 145)];
    [self.view addSubview: bgImage];
    bgImage.image = ImageName(@"d_head_bg");
    
    UILabel *zongYeLB = [[UILabel alloc]init];
    [bgImage addSubview:zongYeLB];
    [zongYeLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.top.equalTo(38);
    }];
    zongYeLB.text = LocalizationKey(@"总业绩（CT）");
    zongYeLB.font = kFont(16);
    zongYeLB.textColor = [UIColor colorWithWhite:1 alpha:0.5];
    
    SYButton *copyBtn = [[SYButton alloc]init];
    [bgImage addSubview:copyBtn];
    [copyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(-20);
        make.centerY.equalTo(zongYeLB);
    }];
    [copyBtn setTitle:[NSString stringWithFormat:@"%@ABCDFE",LocalizationKey(@"邀请码：")] forState:UIControlStateNormal];
    [copyBtn setTitleColor:[UIColor colorWithWhite:1 alpha:0.7] forState:UIControlStateNormal];
    copyBtn.titleLabel.font = kFont(14);
    [copyBtn setImage:ImageName(@"m_copy") forState:UIControlStateNormal];
    copyBtn.btnType = RIGHT;
    
    self.countLB = [[UILabel alloc]init];
    [bgImage addSubview:self.countLB];
       [self.countLB mas_makeConstraints:^(MASConstraintMaker *make) {
           make.left.equalTo(zongYeLB.mas_left);
           make.top.equalTo(74);
       }];
       self.countLB.text = @"0.0000";
       self.countLB.font = kFontPF_Bold(36);
       self.countLB.textColor = [UIColor whiteColor];
    
    self.cInviteBtn = [[UIButton alloc]init];
    [bgImage addSubview:self.cInviteBtn];
    [self.cInviteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(-20);
        make.centerY.equalTo(self.countLB);
        make.height.equalTo(37);
    }];
    [self.cInviteBtn setTitle:[NSString stringWithFormat:@"   %@   ",LocalizationKey(@"复制邀请链接")] forState:UIControlStateNormal];
    [self.cInviteBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.cInviteBtn.titleLabel.font = kFont(14);
    self.cInviteBtn.layer.cornerRadius = 37.0/2.0;
    self.cInviteBtn.layer.borderWidth = 1;
    self.cInviteBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.cInviteBtn addTarget:self action:@selector(cInviteBtnAct) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.layer.cornerRadius = 5.0;
    self.tableView.layer.shadowColor = [UIColor colorWithHEX:@"6E6E6E"].CGColor;
    self.tableView.layer.shadowOffset = CGSizeMake(0, 0);
    self.tableView.layer.shadowOpacity = 0.15;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.frame = CGRectMake(16, 161, kWindowW-32, kWindowH-161);
    self.tableView.rowHeight = 54;
    self.tableView.tableFooterView = [UIView new];
    if (@available(iOS 11.0, *)){
        self.tableView.estimatedRowHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
        self.tableView.estimatedSectionFooterHeight = 0;//防止刷新指定行时，偏移量改变
    }
    
    [self.tableView reloadData];
}

- (void)cInviteBtnAct{
    [self.view makeToast:LocalizationKey(@"copyscuuses") duration:1.5 position:CSToastPositionCenter];
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = @"www.";
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count+5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyTeamCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"id"];
    if (cell == nil) {
        cell = [[MyTeamCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"id"];
    }
//    if (indexPath.row == 0) {
        [cell upDataModel:[[NSDictionary alloc]init] indexInt:indexPath.row];
//    }
//    else{
//        [cell upDataModel:self.dataArr[indexPath.row - 1] indexInt:indexPath.row];
//    }
    
    return cell;
   
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    // indexPath.row 从1开始
    NSLog(@"%ld",(long)indexPath.row);
    
    MyTeamSonVC *VC = [[MyTeamSonVC alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
